package com.obas.access.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ease.platform.access.service.impl.AbstractNamespaceAccessServiceImpl;
import com.obas.access.business.service.SystemFunctionAccessService;
import com.obas.access.business.service.TestcaseScriptAccessService;
import com.obas.model.business.SystemFunction;
import com.obas.model.business.TestcaseScript;

public class TestcaseScriptAccessServiceImpl extends AbstractNamespaceAccessServiceImpl<TestcaseScript> implements TestcaseScriptAccessService {

	private SystemFunctionAccessService systemFunctionAccessService;

	public List<TestcaseScript> findBySystemFunctionId(long systemFunctionId) {
		// TestcaseScriptCriteria parameter = new TestcaseScriptCriteria();
		// parameter.setSystemFunctionId(systemFunctionId);

		SystemFunction systemFunction = systemFunctionAccessService.findById(systemFunctionId);
		if (null != systemFunction) {			
			if(systemFunction.getTestcaseScriptId()>0){
				TestcaseScript testcaseScript = this.findById(systemFunction.getTestcaseScriptId());
				if(null!=testcaseScript) {
					List<TestcaseScript> testcaseScripts = new ArrayList<TestcaseScript>();
					testcaseScripts.add(testcaseScript);
					return testcaseScripts;
				}				
			}			
		}
		return null;
	}

	public TestcaseScript createEntity(TestcaseScript testcaseScript, long systemFunctionId) {
		testcaseScript = this.create(testcaseScript);

		SystemFunction systemFunction = systemFunctionAccessService.findById(systemFunctionId);
		if (null != systemFunction) {
			systemFunction.setTestcaseScriptId(testcaseScript.getId());
			systemFunctionAccessService.update(systemFunction);
		}

		return testcaseScript;
	}

	/**
	 * @return the systemFunctionAccessService
	 */
	public SystemFunctionAccessService getSystemFunctionAccessService() {
		return systemFunctionAccessService;
	}

	/**
	 * @param systemFunctionAccessService
	 *            the systemFunctionAccessService to set
	 */
	public void setSystemFunctionAccessService(SystemFunctionAccessService systemFunctionAccessService) {
		this.systemFunctionAccessService = systemFunctionAccessService;
	}

}
